package com.xyy.saas.payment.service.impl;

import com.xyy.saas.payment.dao.mapper.SeparateOrderMapper;
import com.xyy.saas.payment.dao.model.SeparateOrder;
import com.xyy.saas.payment.service.SeparateOrderService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * (SeparateOrder)表服务实现类
 *
 * @author makejava
 * @since 2020-10-09 10:23:34
 */
@Service("separateOrderService")
public class SeparateOrderServiceImpl implements SeparateOrderService {
    @Resource
    private SeparateOrderMapper separateOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public SeparateOrder queryById(Long id) {
        return this.separateOrderDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<SeparateOrder> queryAllByLimit(int offset, int limit) {
        return this.separateOrderDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param separateOrder 实例对象
     * @return 实例对象
     */
    @Override
    public SeparateOrder insert(SeparateOrder separateOrder) {
        this.separateOrderDao.insert(separateOrder);
        return separateOrder;
    }

    @Override
    public SeparateOrder querySeparateOrderBySeparateNo(String separateNo) {
        return separateOrderDao.queryBySeparateNo(separateNo);
    }

    @Override
    public SeparateOrder querySeparateOrderByRefundSettleNo(String refundSettleNo) {
        return separateOrderDao.queryByRefundSettleNo(refundSettleNo);
    }

    @Override
    public void updateSeparateOrderStatusBySeparateNo(String separateNo, String status) {
        separateOrderDao.updateStatusBySeparateNo(separateNo, status, new Date());
    }

    @Override
    public List<SeparateOrder> querySeparateOrderByBusinessOrderNo(String businessOrderNo) {
       return separateOrderDao.selectByBusinessOrderNo(businessOrderNo);
    }

    @Override
    public List<SeparateOrder> selectListByBusinessOrderNos(List<String> businessOrderNos) {
        if (CollectionUtils.isEmpty(businessOrderNos)) {
            return Collections.emptyList();
        }
        return separateOrderDao.selectListByBusinessOrderNos(businessOrderNos);
    }

    @Override
    public SeparateOrder queryOneByBusinessOrderNo(String businessOrderNo) {
        return separateOrderDao.queryOneByBusinessOrderNo(businessOrderNo);
    }

    @Override
    public void updateSeparateNoById(String separateNo, Long id) {
        separateOrderDao.updateSeparateNoById(separateNo, new Date(), id);
    }

    /**
     * 修改数据
     *
     * @param separateOrder 实例对象
     * @return 影响行数
     */
    @Override
    public int update(SeparateOrder separateOrder) {
        return separateOrderDao.update(separateOrder);
    }
}